var ground = new Ground(positionX, positionY, td * squareWidth, tr * squareWidth);
ground.init = function () {
    this.viewContent.style.position = 'absolute';
    this.viewContent.style.left = this.x + 'px';
    this.viewContent.style.top = this.y + 'px';
    this.viewContent.style.width = this.width + 'px';
    this.viewContent.style.height = this.height + 'px';
    this.viewContent.style.backgroundColor = 'orange';

    document.body.appendChild(this.viewContent);

    //把场景中的小方块都存起来，结构为二维数组，对应的是行与列
    this.squareTable=[
        [],
        [],
        [],
        []
    ];

    //同一行的y轴值相同；同一列的x轴值相同
    for (var y = 0; y < tr; y++) {   //外层循环走的是行数，对应的是y轴的值
        this.squareTable[y]=new Array(td);
        for (var x = 0; x < td; x++) {  //里层循环走的是列数，对应的是x轴的值
            if (x == 0 || x == td - 1 || y == 0 || y == tr - 1) {
                //这个条件成立，说明走的是围墙的位置。要创建围墙
                var newSquare=SquareFactory.create('Wall',x,y,'black');
            } else {
                //这个条件成立，说明走的是地板的位置。要创建地板
                var newSquare=SquareFactory.create('Floor',x,y,'grey');
            }
            //console.log(newSquare);
            this.squareTable[y][x]=newSquare;
            this.viewContent.appendChild(newSquare.viewContent);
        }
    }
    //console.log(this.squareTable);
};

// ground.init();

//移除场景中的小方块
ground.remove=function(x,y){
    var curSquare=this.squareTable[y][x];
    //在DOM里删除
    this.viewContent.removeChild(curSquare.viewContent);

    //在数据里删除 
    this.squareTable[y][x]=null;
};

//ground.remove(1,1);

//添加场景中的小方块
ground.append=function(square){
    //添加到DOM
    this.viewContent.appendChild(square.viewContent);

    //添加到数据里
    this.squareTable[square.y][square.x]=square;
};